<?php 
define('PAGE_NEED_PRI','PRI_EDIT');
session_start();
include("main.php");
include("../inc/JSON.php");
include("blog-main-edit-function.php");
?>
<?php 
$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
switch($action)
{
	case 'new':
		$_REQUEST['callbacklink'] = 'blog-main.php';
		$info = get_table_empty_row(constant('DATA_TABLE_NAME'));
		$info['isok'] = '0';
	break;
	case 'del_images':
		del_images_block();
		$info = fetch_row_data($_REQUEST["id"],$error);
		break;
	break;
	case 'save':
		$_REQUEST['lb'] = isset($_REQUEST['lb'])?$_REQUEST['lb']:'';
		$_REQUEST['BigClassName'] = isset($_REQUEST['BigClassName'])?$_REQUEST['BigClassName']:'';
		$_REQUEST['BigClassName2'] = isset($_REQUEST['BigClassName2'])?$_REQUEST['BigClassName2']:'';
		$_REQUEST['addname'] = isset($_REQUEST['addname'])?$_REQUEST['addname']:'';
		
		if(empty($_REQUEST['callbacklink']))
				$_REQUEST['callbacklink'] = 'blog-main.php';
				
		$error = false;
		if(isset($_REQUEST['lock']))
		{
			$callbacklink = 'blog-main-lock.php';
			if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0)
				$articleid = $_REQUEST['id'];
			else
				$articleid  = false;
			$canlock = check_article_lockable($_REQUEST['BigClassName'],$_REQUEST['BigClassName2'],$articleid);
			if(!$canlock)
			{
			echo "<script>alert('鎖定失敗,子分區鎖定篇數最多五則');window.location.href='".$callbacklink."';</script>";
			$error = true;
			exit();
			}
		}
		if(isset($_REQUEST['lock2']))
		{
			$callbacklink = 'blog-main-lock.php';
			if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0)
				$articleid = $_REQUEST['id'];
			else
				$articleid  = false;
			$canlock = check_article_lockable($_REQUEST['BigClassName'],'',$articleid);
			if(!$canlock)
			{
			echo "<script>alert('鎖定失敗,news鎖定篇數最多五則');window.location.href='".$callbacklink."';</script>";
			$error = true;
			exit();
			}
		}
		if($error === false)
		{
		$result = save_block();
		if($result){
	
			
				
			if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0)
			{
					
			 		echo "<script>alert('資料修改成功！');window.location.href='".$_REQUEST['callbacklink']."';</script>";
			}else{
					echo "<script>alert('資料新增成功！');window.location.href='".$_REQUEST['callbacklink']."';</script>";
			}
		}else{
				if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0)
				{
					echo "<script>alert('資料修改失敗！');</script>";
				}else{
					echo "<script>alert('資料新增失敗！');</script>";
				}
		}
		}
	break;
	default:
		$info = fetch_row_data($_REQUEST["id"],$error);
		if($info === false)
		{
			exit($error);
		}
	break;
}
$articleID = intval($_REQUEST['articleID']);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Bios 管理中心 </title>
<link href="../css/control2.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.5.2.min.js"  language="javascript" ></script>
<script src="uploadify/swfobject.js"  language="javascript" ></script>
<script src="uploadify/jquery.uploadify.v2.1.4.min.js"  language="javascript" ></script>
<link href="uploadify/uploadify.css" rel="stylesheet" type="text/css" />

<script src="../js/jquery.Jcrop.min.js"  language="javascript" ></script>
<link href="../css/crop/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

</head>
<body>
<div id="cropdialog" title="Crop image"></div>
<?php
	$json_service = new Services_JSON();
	$catalog_jsonStr = $json_service->_encode($GLOBALS['ARTICLE_CATALOG']);
	$author_list_jsonStr = $json_service->_encode(get_author_list());
	?>
<script language="javascript">
	var global_catalog_table = <?php echo $catalog_jsonStr;?>;
	var global_author_list = <?php echo $author_list_jsonStr;?>;
	var global_bigClassName = '<?php echo html_safe($info['BigClassName']);?>';
	var global_bigClassName2 = '<?php echo html_safe($info['BigClassName2']);?>';
	var global_author_name = '<?php echo html_safe($info['addname']);?>';
	var global_style = '<?php echo html_safe($info['lb']);?>';
	<?php for( $i=1; $i < 16;$i++):?>
	var global_extraread_<?php echo $i;?> = '<?php echo html_safe($info['c'.$i]);?>';
	<?php endfor;?>
	//Add Event and bind event
	$(function(){
			//select article style option
			$("input[type=radio][name=lb][value="+global_style+"]").attr("checked",'checked'); 
			
			//display big catalog list
			for(var catalogName in global_catalog_table)
			{
				if(global_bigClassName == catalogName)
				{
						$('#bigcatalogcontainer').append('<li> <input name="BigClassName" type="radio" value="'+catalogName+'" checked="checked" />'+catalogName+'</li>');
			  }else{
			  		$('#bigcatalogcontainer').append('<li> <input name="BigClassName" type="radio" value="'+catalogName+'" />'+catalogName+'</li>');
			  }
			}
			//Bind event hand
			$('#bigcatalogcontainer input').bind('change',function(){
							if($(this).attr('checked') == false)
								return false;
								
							var currentBigCatalogName = $(this).val();
							//second catalog
							$('#secondcatalogcontainer').html('<li> 選擇分類：</li>');
							var data_list = global_catalog_table[currentBigCatalogName];
						  for(var indexKey in data_list)
						  {
						  	  var catalogName = data_list[indexKey];
						  	  if(global_bigClassName2 == catalogName)
						  	  {
						  	  		$('#secondcatalogcontainer').append('<li> <input name="BigClassName2" type="radio" value="'+catalogName+'" checked="checked"/>'+catalogName+'</li>');
	
						  	  }else{
						  	  		$('#secondcatalogcontainer').append('<li> <input name="BigClassName2" type="radio" value="'+catalogName+'" />'+catalogName+'</li>');
						  	  }
						  }
						  //author list
						  $('#authorcontainer').html('<li> 作者選擇：</li>');
						  var tm_no_confilict_line_167_catalogName = $("input[name='BigClassName']:checked").val();
						 if(tm_no_confilict_line_167_catalogName == "Feature"||
						 tm_no_confilict_line_167_catalogName == "Column"||
						 tm_no_confilict_line_167_catalogName == "News"||
						 tm_no_confilict_line_167_catalogName == "Event")
						 {
						 	//add no author selcet option
									if(global_author_name == '')
						  			{
						  						$('#authorcontainer').append('<li> <input name="addname" type="radio" value="" checked="checked"/>無</li>');
	
						  			}else{
						  					$('#authorcontainer').append('<li> <input name="addname" type="radio" value="" />無</li>');
						  }						 }
						 for(var indexKey in global_author_list)
						  {
						  		var autho_data = global_author_list[indexKey];
						  		if(autho_data[currentBigCatalogName] == '1')
						  		{
						  			if(global_author_name == autho_data['username'])
						  			{
						  						$('#authorcontainer').append('<li> <input name="addname" type="radio" value="'+autho_data['username']+'" checked="checked"/>'+autho_data['name']+'</li>');
	
						  			}else{
						  					$('#authorcontainer').append('<li> <input name="addname" type="radio" value="'+autho_data['username']+'" />'+autho_data['name']+'</li>');
						  			}
						  		}
						  }
				});
			//trigger event
			$('#bigcatalogcontainer input').trigger("change");
			
			
			//Init style option list event hander
			$('#styleoptioncontainer input').bind('change',function(){
						if($(this).attr('checked') == false)
								return false;
						
						//$('#uploadpanel_1 input').attr("disabled",true);
						//$('#uploadpanel_2 input').attr("disabled",true);
						//$('#uploadpanel_3 input').attr("disabled",true);
								
						$('#uploadpanel_1').hide();
						$('#uploadpanel_2').hide();
						$('#uploadpanel_3').hide();
					
						
						
						
						//$('#uploadpanel_'+$(this).val()+' input').attr("disabled",false);
						$('#uploadpanel_'+$(this).val()).show();
						if($(this).val() == '4')
							$('#uploadpanel_1').show();
						//content editor
						$('#contenteditorpanel_1').hide();
						$('#contenteditorpanel_2').hide();
						//$('#contenteditorpanel_3').hide();
						$('#contenteditorpanel_4').hide();
						
						switch($(this).val())
						{
							case '1':
							case '4':
								$('#contenteditorpanel_1').show();
							break;
							case '2':
								$('#contenteditorpanel_2').show();
								//$('#contenteditorpanel_3').show();
							break;
							case '3':
								$('#contenteditorpanel_4').show();
							break;
						}
				});
				$('#styleoptioncontainer input').trigger("change");
				
				//Init extra read options
				var index = 1;
				for(var key in global_catalog_table)
				{
					for(var key2 in global_catalog_table[key])
					{
							var expreStr = "global_extraread_"+index + "== '1'";
							if(eval(expreStr))
							{
									$('#extrareadpanel').append('<li><input name="extraread_'+index+'" type="checkbox" value="'+key2+'" checked="checked"/> '+global_catalog_table[key][key2]+' </li>');

							}else{
									$('#extrareadpanel').append('<li><input name="extraread_'+index+'" type="checkbox" value="'+key2+'" /> '+global_catalog_table[key][key2]+' </li>');
							}
							
							index++;
					}
				}
				//init file upload
				$(".uploadifyupload").each(function(){
					var current_id = $(this).attr('id');
					var previous_img_id = current_id + '_img';
					var catalog = $('input[name=BigClassName2]').val();
					$(this).uploadify({
						'uploader': 'uploadify/uploadify.swf',
						'cancelImg': 'uploadify/cancel.png',
						'script': 'upload.php',
						'folder': 'files',
						'buttonText':'Choose',
						'multi': false,
						'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
  						'fileDesc':'Image Files',
						'auto': true,
						'queueSizeLimit':1,
						'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','name':$(this).attr('name'),'catalog':catalog,'responsetype':'sizeinfo'},
						'displayData': 'speed',
						'onComplete':function(event,queueID,fileObj,response,data){
							var responseObj = eval("("+response+")");
							var fileName = responseObj.name;
							
							//if in download mode image2 and image3
							if(current_id == 'dow_images2' || current_id == 'dow_images3')
							{
								$('#'+previous_img_id).attr('src','../upfiles/tmp/' + fileName);
								$('input[name=ajaxf_'+current_id+']').val(fileName);		
								return true;
							}
							var i_width = responseObj.w;
							var i_height = responseObj.h;
							var i_show_height = 300;
							var i_scale = i_show_height/i_height;
							var i_show_width = i_width*i_scale;
							
							var crop_width = 1080;
							var crop_height = 595;
					
							var lb = $("input[name=lb]:checked").val();
							if(lb == 1 || lb == 4)
							{
								//mix old stle
								crop_width = 600;
								crop_height = 400;
							}else if(lb == 3)
							{
								//download
								crop_width = 890;
								crop_height = 492;
							}
							if(i_width < i_height)
							{
								crop_width = 267;
								crop_height = 400;
							}
							var crop_show_width = crop_width*i_scale;
							var crop_show_height = crop_height*i_scale;
							
							
							var crop_box_x = (i_show_width - crop_show_width)/2;
							var crop_box_y = (i_show_height - crop_show_height)/2;
							
						
							var select_x;
							var select_y;
							var select_w;
							var select_h;
							
							$( "#cropdialog").dialog({
							 	'width':i_show_width + 50,
							 	'height':i_show_height + 128,
								buttons:[{'text':'OK','click':function(){
									p_src = "tmp/" + fileName;
									var crop_file_name = fileName + "."+crop_width+"x"+crop_height+".jpg";
									p_des = "tmp/" + crop_file_name;
									
									p_width = crop_width;
									p_height = crop_height;
									p_c_x = select_x/i_scale;
									p_c_y = select_y/i_scale;
									p_c_width = select_w/i_scale;
									p_c_height = select_h/i_scale;
			
									$.post("crop.php", {'src': p_src,'des':p_des,'width':p_width,'height':p_height,'c_x':p_c_x,'c_y':p_c_y,'c_width':p_c_width,'c_height':p_c_height},function(date){							
										$('#'+previous_img_id).attr('src','../upfiles/tmp/' + crop_file_name);
										$('input[name=ajaxf_'+current_id+']').val(crop_file_name);
										$( "#cropdialog").html('');
										$( "#cropdialog").dialog("destroy");
									});

								}}]
							});
							$( "#cropdialog").html("<img src='../upfiles/tmp/"+fileName+"' id='cropbox' width='"+i_show_width+"' height='"+i_show_height+"'/> ");
							$('#cropbox').Jcrop({ 
							onSelect:function(c){
								select_x = c.x;
								select_y = c.y;
								select_w = c.w;
								select_h = c.h;							
								
							},
							/*setSelect:[crop_box_x, crop_box_y,crop_box_x + crop_show_width, crop_box_y + crop_show_height],*/
							aspectRatio:crop_width/crop_height});
						},
						'onError':function(event,queueId,fileObj,errorObj){
							alert(errorObj);
						}
					});
				});
					
	});
function check_form(form)
{

	if($("input[name='lb']:checked").val() == undefined)
	{
		alert('請填寫文章格式');
		return false;
	}
	if(form.title.value == '')
	{
		alert("請填寫文章標題.");
		return false;
	}
	var catalogName = $("input[name='BigClassName']:checked").val();
	if(catalogName == 'Column')
	{
		if($("input[name='addname']:checked").val() == undefined)
		{
			alert("請選擇作者");
			return false;
		}
	}
	form.submit();
}
</script>

<script language="javascript">
/****************
* 由于字数限制，请下载附件看使用说明．
*******如果您使用本日历控件 请保留该信息 谢谢! ***********   
* http://2lin.net
* Email:caoailin@gmail.com 
* QQ:38062022 
* Creation date: 2006-11-22 
******************/


function Calendar(objName)  

{  
this.style = {
borderColor         : "#909eff", //边框颜色
headerBackColor      : "#909EFF", //表头背景颜色
headerFontColor      : "#ffffff", //表头字体颜色
bodyBarBackColor    : "#f4f4f4", //日历标题背景色
bodyBarFontColor    : "#000000", //日历标题字体色
bodyBackColor       : "#ffffff", //日历背景色
bodyFontColor            : "#000000", //日历字体色 
bodyHolidayFontColor     : "#ff0000", //假日字体色
watermarkColor       : "#d4d4d4",  //背景水印色
moreDayColor             : "#cccccc" 
};
this.showMoreDay = false; //是否显示上月和下月的日期
this.Obj = objName;  
this.date = null;
this.mouseOffset = null;
this.dateInput = null;
this.timer = null; 
};
Calendar.prototype.toString = function()
{   
var str = this.getStyle();
str += '<div Author="alin" class="calendar" style="display:none;" onselectstart="return false" oncontextmenu="return false" id="Calendar">\n';
str += '<div Author="alin" class="cdrWatermark" id="cdrWatermark"></div><div id="cdrBody" style="position:absolute;left:0px;top:0px;z-index:2;width:140px;">';
str += this.getHeader();
str += this.getBody();   
str += '</div><div Author="alin" id="cdrMenu" style="position:absolute;left:0px;top:0px;z-index:3;display:none;"  onmouseover="' + this.Obj + '.showMenu(null);" onmouseout="' + this.Obj + '.hideMenu();"></div></div>';
return str;
};
Calendar.prototype.getStyle = function()
{
var str = '<style type="text/css">\n';
str += '.calendar{position:absolute;width:140px!important;width /**/:142px;height:212px!important;height /**/:174px;background-color:'+this.style.bodyBackColor+';border:1px solid ' + this.style.borderColor + ';left:0px;top:0px;z-index:9999;}\n';
str += '.cdrHeader{background-color:'+ this.style.headerBackColor +';width:140px;height:22px;font-size:12px;color:'+this.style.headerFontColor+';}\n';
str += '.cdrWatermark{position:absolute;left:0px;top:80px;width:140px;font-family: Arial Black;font-size:50px;color:'+this.style.watermarkColor+';z-index:1;text-align:center;}\n';
str += '.cdrBodyBar{background-color:' + this.style.bodyBarBackColor + ';font-size:12px;color:' + this.style.bodyBarFontColor + ';width:140px;height:20px;}\n';
str += '.cdrBody{width:140px;height:122px!important; height /**/:110px;font-size:12px;cursor:pointer;color:' + this.style.bodyFontColor + ';}\n';
str += '.dayOver{height:16px;padding:0px;border:1px solid black;background-color:#f4f4f4;}\n';
str += '.dayOut{padding:1px;border:none;height:16px;}\n';
str += '.menuOver{background-color:'+this.style.headerBackColor+';color:'+this.style.headerFontColor+';font-size:12px;}\n';
str += '.headerOver{border:1px solid black;background-color:#f4f4f4;color:black;cursor:default;}\n';
str += '.cdrMenu{font-size:12px;border:1px solid #000000;background-color:#ffffff;cursor:default;width:100%}\n';
str += 'html>body #Calendar{width:142px;174px;}';
str += '</style>\n'; 
return str;
};
Calendar.prototype.getHeader = function()
{
var str = '<table Author="alin" class="cdrHeader" cellSpacing="2" cellPadding="0"><tr Author="alin" align="center">\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="previousYear" title="上一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(false);"><<</td>\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="previousMonth" title="上一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(false);"><</td>\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" id="currentYear" style="width:50px;" onclick="' + this.Obj + '.showMenu(true);" onmouseout="' + this.Obj + '.hideMenu();this.className=\'\';">0</td>\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" id="currentMonth" onclick="' + this.Obj + '.showMenu(false);" onmouseout="' + this.Obj + '.hideMenu();this.className=\'\';">0</td>\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="nextMonth" title="下一月份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeMonth(true);">></td>\n';
str += '<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" id="nextYear" title="下一年份" style="cursor:pointer;width:10px;" onclick="'+this.Obj+'.onChangeYear(true);">>></td></tr>\n';
str += '</table>\n';
return str;
};
Calendar.prototype.getBody = function()
{
var n = 0;
var str = this.getBodyBar();
str += '<table Author="alin" class="cdrBody" cellSpacing="2" cellPadding="0">\n';   
for(i = 0; i < 6; i++)
{   
str += '<tr Author="alin" align="center">';
for(j = 0; j < 7; j++)
{
str += '<td Author="alin" class="dayOut" id="cdrDay'+(n++)+'" width="13%"></td>\n';
}
str += '</tr>';
}
str += '</table>\n';
str += '<table Author="alin" class="cdrBodyBar" cellSpacing="2" cellPadding="0" ><tr align="center" Author="alin"><td Author="alin" valign="top" style="cursor:pointer;" onclick="'+this.Obj+'.getToday();">今天：'+new Date().toFormatString("yyyy年mm月dd日")+'</td></tr></table>\n';



return str;

};

Calendar.prototype.getBodyBar = function()
{
var str = '<table Author="alin_bar" id="cdrBodyBar" class="cdrBodyBar" style="cursor:move;" cellSpacing="2" cellPadding="0"><tr Author="alin_bar" align="center">\n';
var day = new Array('日','一','二','三','四','五','六');
for(i = 0; i < 7; i++)
{
str += '<td Author="alin_bar">' + day[i] + '</td>\n';     
}
str += '</tr></table>';
return str;  
}
Calendar.prototype.getYearMenu = function(year)
{
var str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">\n';
for(i = 0; i < 10; i++)
{   
var _year = year + i;
var _date = new Date(_year,this.date.getMonth(),this.date.getDate());
str += '<tr Author="alin" align="center"><td Author="alin" width="13%" height="16" ';
if(this.date.getFullYear() != _year)
{
str += 'style="color:#000000" ';//111111111
str += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
}
else
{
str += 'style="color:#FF0000" ';//111111111
}
str += 'onclick="' + this.Obj + '.bindDate(\'' + _date.toFormatString("-") + '\')">' + _year + '年</td>\n';  
str += '</tr>';
}
str += '<tr Author="alin" align="center"><td Author="alin"><table Author="alin" style="font-size:12px;width:100%;" cellSpacing="0" cellPadding="0">\n';
str += '<tr Author="alin" align="center"><td  style="color:#000000"  Author="alin" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" onclick="'+this.Obj+'.getYearMenu('+ (year - 10) + ')"><<</td>\n';
str += '<td style="color:#000000" Author="alin" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" onclick="'+this.Obj+'.getYearMenu('+ (year + 10) +')">>></td><tr>\n';
str += '</table></td></tr>\n';
str += '</table>';
var _menu = getObjById("cdrMenu");
_menu.innerHTML = str;
};
Calendar.prototype.getMonthMenu = function()
{
var str = '<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0">\n';
for(i = 1; i <= 12; i++)
{   
var _date = new Date(this.date.getFullYear(),i-1,this.date.getDate());  
str += '</tr><tr Author="alin" align="center"><td Author="alin" height="16" ';
if(this.date.getMonth() + 1 != i)
{
str += 'style="color:#000000" ';//111111111
str += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
}
else
{
str += 'style="color:#FF0000" ';//111111111
}
str += 'onclick="' + this.Obj + '.bindDate(\'' + _date.toFormatString("-") + '\')">'+i+'月</td></tr>\n';
}
str += '</table>';
var _menu = getObjById("cdrMenu");
_menu.innerHTML = str;   
};
Calendar.prototype.show = function()
{
if (arguments.length >  3  || arguments.length == 0)
{
alert("對不起！傳入參數不對！" );
return;
}   
var _date = null;
var _evObj = null;
var _initValue = null  
for(i = 0; i < arguments.length; i++)
{
if(typeof(arguments[i]) == "object"  &&  arguments[i].type == "text")
{_date = arguments[i];}
else if(typeof(arguments[i]) == "object")
{_evObj = arguments[i];}
else if(typeof(arguments[i]) == "string")
{_initValue = arguments[i];}  
}
_evObj = _evObj || _date;
inputObj = _date;
targetObj = _evObj
if(!_date){alert("傳放參數錯誤!"); return;}
this.dateInput = _date;
_date = _date.value;
if(_date == ""  &&  _initValue) _date = _initValue;   
this.bindDate(_date);        
var _target = getPosition(_evObj);   
var _obj = getObjById("Calendar");
_obj.style.display = ""; 
_obj.style.left = _target.x + 'px';
if((document.body.clientHeight - (_target.y + _evObj.clientHeight)) >= _obj.clientHeight)
{        
_obj.style.top = (_target.y + _evObj.clientHeight) + 'px';
}
else
{   
_obj.style.top = (_target.y - _obj.clientHeight) + 'px';
}
};
Calendar.prototype.hide = function()
{
var obj = getObjById("Calendar");
obj.style.display = "none";   
};
Calendar.prototype.bindDate = function(date)
{
var _monthDays = new Array(31,30,31,30,31,30,31,31,30,31,30,31); 
var _arr = date.split('-');  
var _date = new Date(_arr[0],_arr[1]-1,_arr[2]); 
if(isNaN(_date)) _date = new Date(); 
this.date = _date;
this.bindHeader(); 
var _year = _date.getFullYear();
var _month = _date.getMonth();
var _day = 1; 
var _startDay = new Date(_year,_month,1).getDay();
var _previYear = _month == 0 ? _year - 1 : _year;
var _previMonth = _month == 0 ? 11 : _month - 1;
var _previDay = _monthDays[_previMonth];
if (_previMonth == 1) _previDay =((_previYear%4==0) && (_previYear%100!=0)||(_previYear%400==0))?29:28; 
_previDay -= _startDay - 1;
var _nextDay = 1;
_monthDays[1] = ((_year%4==0) && (_year%100!=0)||(_year%400==0))?29:28;
for(i = 0; i < 40; i++)
{ 
var _dayElement = getObjById("cdrDay" + i);
_dayElement.onmouseover = Function(this.Obj + ".onMouseOver(this)");
_dayElement.onmouseout = Function(this.Obj + ".onMouseOut(this)");
_dayElement.onclick = Function(this.Obj + ".onClick(this)");
this.onMouseOut(_dayElement);    
_dayElement.style.color = "";
if(i < _startDay)
{
//获取上一个月的日期
if(this.showMoreDay)
{
var _previDate = new Date(_year,_month - 1,_previDay);
_dayElement.innerHTML = _previDay;
_dayElement.title = _previDate.toFormatString("yyyy年mm月dd日");
_dayElement.value = _previDate.toFormatString("-"); 
_dayElement.style.color = this.style.moreDayColor; 
_previDay++;
}else
{
_dayElement.innerHTML = "";
_dayElement.title = "";
}
}
else if(_day > _monthDays[_month])
{
//获取下个月的日期
if(this.showMoreDay)
{
var _nextDate = new Date(_year,_month + 1,_nextDay);
_dayElement.innerHTML = _nextDay;
_dayElement.title = _nextDate.toFormatString("yyyy年mm月dd日");
_dayElement.value = _nextDate.toFormatString("-");
_dayElement.style.color = this.style.moreDayColor; 
_nextDay++;      
}else
{
_dayElement.innerHTML = "";
_dayElement.title = "";
}
}
else if(i >= new Date(_year,_month,1).getDay()  &&  _day <= _monthDays[_month])
{
//获取本月日期
_dayElement.innerHTML = _day;
if(_day == _date.getDate())
{
this.onMouseOver(_dayElement);
_dayElement.onmouseover = Function("");   
_dayElement.onmouseout = Function("");               
}
if(this.isHoliday(_year,_month,_day))
{
_dayElement.style.color = this.style.bodyHolidayFontColor;     
}
var _curDate = new Date(_year, _month, _day);
_dayElement.title =  _curDate.toFormatString("yyyy年mm月dd日");
_dayElement.value = _curDate.toFormatString("-");
_day++;
}
else
{
_dayElement.innerHTML = "";
_dayElement.title = "";
} 
}
var _menu = getObjById("cdrMenu");
_menu.style.display = "none"; 
};
Calendar.prototype.bindHeader = function()
{
var _curYear = getObjById("currentYear");
var _curMonth = getObjById("currentMonth");
var _watermark = getObjById("cdrWatermark");
_curYear.innerHTML = this.date.toFormatString("yyyy年");
_curMonth.innerHTML =  this.date.toFormatString("mm月");
_watermark.innerHTML = this.date.getFullYear();     
}; 
Calendar.prototype.getToday = function()
{
var _date = new Date();
this.bindDate(_date.toFormatString("-"));
}; 
Calendar.prototype.isHoliday = function(year,month,date)
{
var _date = new Date(year,month,date);
return (_date.getDay() == 6 || _date.getDay() == 0);
};
Calendar.prototype.onMouseOver = function(obj)
{
obj.className = "dayOver";
};
Calendar.prototype.onMouseOut = function(obj)
{
obj.className = "dayOut";
}; 
Calendar.prototype.onClick = function(obj)
{  
if(obj.innerHTML != "")  this.dateInput.value = obj.value;
this.hide();
};
Calendar.prototype.onChangeYear = function(isnext)
{
var _year = this.date.getFullYear();
var _month = this.date.getMonth() + 1;
var _date = this.date.getDate();
if(_year > 999  &&  _year <10000)
{
if(isnext){_year++;}else{ _year --;}
}
else
{
alert("年份超出范圍（1000-9999）!");
}
this.bindDate(_year + '-' + _month + '-' + _date);
};
Calendar.prototype.onChangeMonth = function(isnext)
{
var _year = this.date.getFullYear();
var _month = this.date.getMonth() + 1;
var _date = this.date.getDate();
if(isnext){ _month ++;} else {_month--;}
if(_year > 999  &&  _year <10000)
{ 
if(_month < 1) {_month = 12; _year--;}
if(_month > 12) {_month = 1; _year++;}
}
else
{
alert("年份超出范围（1000-9999）!");
}  
this.bindDate(_year + '-' + _month + '-' + _date);
};
Calendar.prototype.showMenu = function(isyear)
{
var _menu = getObjById("cdrMenu");
if(isyear != null)
{    
var _obj = (isyear)? getObjById("currentYear") : getObjById("currentMonth");
if(isyear)
{
this.getYearMenu(this.date.getFullYear() - 5);    
}
else
{
this.getMonthMenu();    
}
_menu.style.top = (_obj.offsetTop + _obj.offsetHeight) + 'px';
_menu.style.left = _obj.offsetLeft + 'px'; 
_menu.style.width = _obj.offsetWidth + 'px';
}
if (this.timer != null) clearTimeout(this.timer);
_menu.style.display="";
}
Calendar.prototype.hideMenu = function()
{
var _obj = getObjById("cdrMenu");
this.timer = window.setTimeout(function(){_obj.style.display='none';},500); 
}
Number.prototype.NaN0 = function()
{
return isNaN(this) ? 0 : this;
}
Date.prototype.toFormatString = function(fs)
{
if(fs.length == 1)
{ 
return this.getFullYear() + fs + (this.getMonth() + 1) + fs + this.getDate(); 
}
fs = fs.replace("yyyy",this.getFullYear());
fs = fs.replace("mm",(this.getMonth() + 1));
fs = fs.replace("dd",this.getDate());
return fs;
}
/************公用方法及变量**************/
var inputObj = null; 
var targetObj = null; 
var dragObj = null; 
var mouseOffset = null; 
function getObjById(obj)
{
if(document.getElementById)
{
return document.getElementById(obj);
}
else
{
alert("流覽器不支持!");
}
}
function mouseCoords(ev)
{
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop  - document.body.clientTop
};
}
function getPosition(e)
{
var left = 0;
var top  = 0;
while (e.offsetParent){
left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
e     = e.offsetParent;
}
left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
return {x:left, y:top};
}
function getMouseOffset(target, ev)
{
ev = ev || window.event;
var docPos    = getPosition(target);
var mousePos  = mouseCoords(ev);
return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}
function closeCalendar(evt){
evt = evt || window.event; 
var _target= evt.target || evt.srcElement; 
if(!_target.getAttribute("Author")  &&   _target != inputObj  &&  _target != targetObj)
{
getObjById("Calendar").style.display = "none";    
}  
}
function dragStart(evt){
evt = evt || window.event; 
var _target= evt.target || evt.srcElement;
if(_target.getAttribute("Author") == "alin_bar") 
{    
dragObj = getObjById("Calendar");    
mouseOffset = getMouseOffset(dragObj, evt);  
}   
}
function drag(evt)
{
evt =  evt || window.event; 
if(dragObj)
{    
var mousePos = mouseCoords(evt); 
dragObj.style.left = (mousePos.x - mouseOffset.x) + 'px';
dragObj.style.top  = (mousePos.y - mouseOffset.y) + 'px';   
}
}
//拖动结束
function dragEnd(evt)
{
dragObj = null;    
}
/***********End 公用方法*********/
document.onclick = closeCalendar;
document.onmousedown = dragStart;
document.onmousemove = drag;
document.onmouseup = dragEnd;
/*********结束**********/


var c = new Calendar("c");
document.write(c);
c.getToday();




</script>
<div id="all"><!--Wrap start //-->
<div id="main" class="clearfix"><!--main start //-->
 <?php include_once('top_btn.php');?>
<?php include_once('blog_main_btn.php');?>
  <div id="contact-add"><!--start contact //-->
<form method="post" enctype="multipart/form-data" name="form1" action="blog-main-edit.php">
<input type="hidden" name="action" value="save"/>
<input type="hidden" name="id" value="<?php echo $info['id']?>"/>
<input type="hidden" name="callbacklink" value="<?php echo !empty($_REQUEST['callbacklink'])?$_REQUEST['callbacklink']:'';?>"/>
<input type="hidden" name="addnamedisplay" value=""/>
<input type="hidden" name="isok" value="<?php echo make_safe($info['isok']);?>"/>
<div class="contact-add-line">
文章標題：<input name="title" type="text" class="contact_add-tit-keyin" value="<?php echo $info['title'];?>"  />
 <ul id='bigcatalogcontainer'>
 <li> 選擇分類：</li>
 </ul>
</div>
<div class="contact-add-line">
	<ul id='secondcatalogcontainer'>
	<li> 子類別選項：</li> 
	</ul>
</div>
<div class="contact-add-line">
 <ul id='authorcontainer'>
 <li> 作者選擇：</li>
 </ul>
</div>

<?php if($info['isok'] == '1'):?>
<div class="contact-add-line">
 <ul>
 <li> 子分區鎖定：<input type="checkbox" name="lock" <?php if($info['lock'] == 'Y'):?>checked="checked"<?php endif;?>/></li>
 <?php
 	if($info['lock_start'] == '0000-00-00 00:00:00')
 	{
 		$info['lock_start'] = date('Y-m-d');
 	}
 	if($info['lock_end'] == '0000-00-00 00:00:00')
 	{
 		$info['lock_end'] = date('Y-m-d');
 	}
 ?>
 <li style="width:180px;">鎖定時間：<input name="lock_start" type="text" style="width:80px" onfocus="c.showMoreDay = false;c.show(this,'<?php echo date('Y-m-d',strtotime($info['lock_start']));?>');" value="<?php echo date('Y-m-d',strtotime($info['lock_start']));?>"></li>
  <li style="width:200px;">鎖定結束時間：<input name="lock_end" type="text" style="width:80px" onfocus="c.showMoreDay = false;c.show(this,'<?php echo date('Y-m-d',strtotime($info['lock_end']));?>');" value="<?php echo date('Y-m-d',strtotime($info['lock_end']));?>"></li>
 <?php if($info['BigClassName'] == 'News'):?>
 <li id="li_nws_lock"> news鎖定 ：<input type="checkbox" name="lock2" <?php if($info['lock2'] == 'Y'):?>checked="checked"<?php endif;?>/></li>
<?php endif;?>
 </ul>
</div>
<?php endif;?>

<div class="contact-add-line" id="styleoptioncontainer">
文章格式選擇：
 <ul>
 <li> 選擇分類：</li>
 <li> <input name="lb" type="radio" value="1" /> 混合格式 </li>
 <li> <input name="lb" type="radio" value="4" /> 混合格式_old </li>
  <li><input name="lb" type="radio" value="2" /> 橫圖格式 </li>
 <li> <input name="lb" type="radio" value="3" /> Download </li>
 </ul>
</div>

<div class="contact-add-line" style="display:none" id='uploadpanel_1'>
混合格式 新增圖片：
 <?php for($i=1;$i<7;$i++):?>
 	<input type="hidden" name="ajaxf_mix_images<?php echo $i;?>" value=""/>
  <p>圖片<?php echo $i;?>：
 		<?php if(($info['lb'] == '1' || $info['lb'] == '4') && strlen($info['images'.$i]) > 0):?>
 				<img id="mix_images<?php echo $i;?>_img" src="../upfiles/<?php echo $info['images'.$i];?>" width="35" height="35" /><a href="?action=del_images&id=<?php echo $info['id'];?>&imgField=images<?php echo $i;?>">刪除</a>
 		<?php else:?>
 						<img id="mix_images<?php echo $i;?>_img" src="../upfiles/default.png" width="35" height="35" />
 
 		<?php endif;?>
 		<input class="uploadifyupload" id="mix_images<?php echo $i;?>" name="mix_images<?php echo $i;?>" type="file" />
   </p>
 <?php endfor;?>
</div>

<div class="contact-add-line" style="display:none" id='uploadpanel_2'>
橫圖格式 新增圖片：
 <?php for($i=1;$i<16;$i++):?>
 <input type="hidden" name="ajaxf_hor_images<?php echo $i;?>" value=""/>
 <p>圖片<?php echo $i;?>：<input name="images<?php echo$i;?>_desc" value="<?php echo make_safe($info['images'.$i.'_desc']);?>" size="50"/>
 	<?php if($info['lb'] == '2' && strlen($info['images'.$i]) > 0):?>
 				<img id="hor_images<?php echo $i;?>_img" src="../upfiles/<?php echo $info['images'.$i];?>" width="35" height="35" /><a href="?action=del_images&id=<?php echo $info['id'];?>&imgField=images<?php echo $i;?>">刪除</a>
 		<?php else:?>
 		 	<img id="hor_images<?php echo $i;?>_img" src="../upfiles/default.png" width="35" height="35" />

 		<?php endif;?>
 		<input class="uploadifyupload" id="hor_images<?php echo $i;?>" name="hor_images<?php echo $i;?>" type="file" />
 		</p>
 <?php endfor;?>
</div>

<div class="contact-add-line" style="display:none" id='uploadpanel_3'>
download 新增圖片：
	<input type="hidden" name="ajaxf_dow_images1" value=""/>
 <p>圖片：
 	<?php if($info['lb'] == '3' && strlen($info['images1']) > 0):?>
 				<img id="dow_images1_img" src="../upfiles/<?php echo $info['images1'];?>" width="35" height="35" /><a href="?action=del_images&id=<?php echo $info['id'];?>&imgField=images1">刪除</a>		
 	<?php else:?>
 				<img id="dow_images1_img" src="../upfiles/default.png" width="35" height="35" />	
 		
 	<?php endif;?>
 	<input class="uploadifyupload" id="dow_images1" name="dow_images1" type="file" />
 	</p>
 	<input type="hidden" name="ajaxf_dow_images2" value=""/>
 <p>下載圖片上傳 尺寸：1680 x 1050 
 		<?php if($info['lb'] == '3' && strlen($info['images2']) > 0):?>
 				<img id="dow_images2_img" src="../upfiles/<?php echo $info['images2'];?>" width="35" height="35" /><a href="?action=del_images&id=<?php echo $info['id'];?>&imgField=images2">刪除</a>		
 		<?php else:?>
 				<img id="dow_images2_img" src="../upfiles/default.png" width="35" height="35" />	
 		
 	<?php endif;?>
 	<input class="uploadifyupload" id="dow_images2" name="dow_images2" type="file" />
 	</p>
 	<input type="hidden" name="ajaxf_dow_images3" value=""/>
 <p>下載圖片上傳 尺寸：1280 x 1024 
 		<?php if($info['lb'] == '3' && strlen($info['images3']) > 0):?>
 				<img id="dow_images3_img" src="../upfiles/<?php echo $info['images3'];?>" width="35" height="35" /><a href="?action=del_images&id=<?php echo $info['id'];?>&imgField=images3">刪除</a>		
 	<?php else:?>
 					<img id="dow_images3_img" src="../upfiles/default.png" width="35" height="35" />	
 
 	<?php endif;?>
 	<input class="uploadifyupload" id="dow_images3" name="dow_images3" type="file" />
 	</p>
</div>

<div class="contact-add-line" style="display:none" id="contenteditorpanel_1">
混合格式 編輯內容：
<?php 
include('../fckeditor/fckeditor.php');
	$oFCKeditor = new FCKeditor('FCKeditor1')  ; 
	$oFCKeditor->BasePath = '../fckeditor/' ;    
	$oFCKeditor->ToolbarSet = 'Default' ; 
	$oFCKeditor->InstanceName = 'content1' ; 
	$oFCKeditor->Width = '100%' ; 
	$oFCKeditor->Height = '400' ; 
	$oFCKeditor->Value  = stripslashes($info['content']); 
	//$oFCKeditor->Value  = $row->content; 
$oFCKeditor->Create();?><br />
<?php if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0):?>
<a href="blog-main-page.php?articleID=<?php echo $info['id'];?>">分頁管理</a>
<?php endif;?>
</div>

<div class="contact-add-line" style="display:none" id="contenteditorpanel_2">
橫圖格式 編輯內容：
<textarea cols="120" rows="10" name="content2"><?php echo $info['content'];?></textarea>
</div>



<div class="contact-add-line" style="display:none" id="contenteditorpanel_4">
Download 編輯內容：
<?php 
include('../fckeditor/fckeditor.php');
	$oFCKeditor = new FCKeditor('FCKeditor1')  ; 
	$oFCKeditor->BasePath = '../fckeditor/' ;    
	$oFCKeditor->ToolbarSet = 'Default' ; 
	$oFCKeditor->InstanceName = 'content4' ; 
	$oFCKeditor->Width = '100%' ; 
	$oFCKeditor->Height = '300' ; 
	$oFCKeditor->Value  = stripslashes($info['content']); 
	//$oFCKeditor->Value  = $row->content; 
$oFCKeditor->Create();?>
</div>

<div class="contact-add-line2">
標簽雲（關鍵字）設定：
  <ul>
<li>
         <label for="textfield3"></label>
         <input name="tagcloud1" type="text" class="contact_tagcloud" id="textfield3" value="<?php echo html_safe($info['tagcloud1']);?>"/>
       </li>
       <li>
         <label for="textfield3"></label>
         <input name="tagcloud2" type="text" class="contact_tagcloud" id="textfield3" value="<?php echo html_safe($info['tagcloud2']);?>"/>
       </li>
       <li>
         <label for="textfield3"></label>
         <input name="tagcloud3" type="text" class="contact_tagcloud" id="textfield3" value="<?php echo html_safe($info['tagcloud3']);?>"/>
       </li>
       <li>
         <label for="textfield3"></label>
         <input name="tagcloud4" type="text" class="contact_tagcloud" id="textfield3" value="<?php echo html_safe($info['tagcloud4']);?>"/>
       </li>
       <li>
         <label for="textfield3"></label>
         <input name="tagcloud5" type="text" class="contact_tagcloud" id="textfield3" value="<?php echo html_safe($info['tagcloud5']);?>"/>
       </li>
 </ul>
</div>

<div class="contact-add-line">
延伸閱讀選擇區塊：
  <ul id="extrareadpanel">
  	

 </ul>
</div>

<div class="contact-add-line">
 <a href="#" onclick="check_form(document.form1);return false;"> 
 	<?php if(isset($_REQUEST['id']) && intval($_REQUEST['id']) > 0):?>
 	<img src="images/edit-btn.gif" width="68" height="16" />
 	<?php else:?>
 	<img src="images/add-btn.gif" width="68" height="16" />
 	<?php endif;?>
 	</a>
  </div>


</form>
  </div><!--end contact //-->
</div><!-- main end //-->
</div><!--Wrap end //-->
<div id="botton">
<?php include_once('botton_btn.php');?>
</div>
</body>
</html>
